#include <cstdio>
#include <iostream>
#include <string>

std::string str[1000];
std::string strraw[1000];
std::string strwt[1000];
int vari[1000][3];
std::string co1[1000];
std::string co2[1000];

int n;
int var;
int k;
int rest;


bool cleanBlack(int i){
	int lg = strraw[i].length;
	for(int k = 0; k < lg; k++){
		if(!isspace(strrqw[i][k])) str[i].append(strrqw[i][k]);
	}
}

bool changeSense(int i){
	int lg = strraw[i].length;
	for(int k = 0; k < lg; k++){
		if(strrqw[i][k] == '-') str[i][k] = '+';
		else if(strrqw[i][k] == '+') str[i][k] = '-';
		else;
	}
}

bool changeNames(int i){
	strwt[i] = str[i];
	for(int k = var-1; k >= 0 ;k--){
		strwt[i].replace(co1[k], co2[k]);
	}
}

bool readNames(FILE* rel){
	int v,u,k,id;
	for(int i = 0; i < var ;i++){
		strwt[i].replace(co1[i], co2[i]);
	}
}


int main (int argc, char *argv[]){
	n = atoi(argv[1]);
	k = atoi(argv[2]);
	var = atoi(argv[3]);
	FILE* out = fopen(argv[4],"w");
	FILE* in = fopen(argv[5],"r");
	FILE* inname = fopen(argv[6],"r");
	std::string read;
	rest = 0;

	readNames(inname);

	while(!feof(in)){
		std::getline(in, read);
		if(read != NULL && read[0] == '('){
			strraw[rest] = read;
			cleanBlack(rest);
			changeNames(rest);
			int lgt = strraw[rest].length();
			int count = lgt - 1;
			while(isdigit(str[count]))count--;
			if(str[count] == '-') changeSense(rest);
			rest++;
		}
	}

	for(int i = 0; i < rest; i++){
		fprintf(out, "%s \n", strwt[i]);
	}

	return 0;
}
